package com.simple.web.controller.business;

import com.github.zuihou.base.R;
import com.simple.business.util.QiNiuYunUtil;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @desc
 * @Author Simple
 * @Date 2025/3/13 14:18
 **/
@Slf4j
@RequestMapping("/file")
@RestController
public class FileController {
    @Resource
    private QiNiuYunUtil qiNiuYunUtil;

    @ApiOperation(value = "图片上传")
    @PostMapping(value = "/uploadImg")
    public R<String> uploadImg(
            @RequestParam(value = "file") MultipartFile file) {
        if (file.isEmpty()) {
            return R.fail("文件异常");
        }

        return R.success(qiNiuYunUtil.uploadImg(file));
    }

    @ApiOperation(value = "删除图片")
    @GetMapping(value = "/deleteImg")
    public R<String> deleteImg(String fileName) {
        return R.success(qiNiuYunUtil.deleteImg(fileName));
    }

}
